/*
 * RemoteTableViewer.java
 * 
 * Written by Joseph Bowbeer and released to the public domain,
 * as explained at http://creativecommons.org/licenses/publicdomain
 */

package jozart.remotetabledemo;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.rmi.RMISecurityManager;

import javax.swing.JFrame;
import javax.swing.table.DefaultTableModel;

/**
 * Views a remote table model. A viewer is just an editor with the
 * editing capability disabled. 
 *
 * @author  Joseph Bowbeer
 * @version 1.1
 */
public class RemoteTableViewer extends RemoteTableEditor {

    /** Initializes the form. */
    public RemoteTableViewer() { }

    /** Creates a default model with cell editing disabled. */
    protected DefaultTableModel createLocalModel() {
        return DemoTableModel.createClientModel(false);
    }


    /**
     * Launches this applet in a frame.
     * @param args ignored
     */
    public static void main(String[] args) {

        /* Create and install a security manager. */
        if (System.getSecurityManager() == null) {
            System.setSecurityManager(new RMISecurityManager());
        }

        final JFrame frame = new JFrame("Remote Table Viewer");
        final RemoteTableViewer applet = new RemoteTableViewer();
        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent event) {
                applet.shutdown(1000);
                System.exit(0);
            }
        });
        frame.getContentPane().add(applet, BorderLayout.CENTER);
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                frame.pack();
                frame.setVisible(true);
                applet.init();
                applet.start();
            }
        });
    }
}
